package gxdlxy.zx2201.utils;

public class Hero {
    protected int atk, def;
    public int hp;
    public String name;

    // 方法重载：函数名一致，但参数类型与数量有所区别
    public Hero(String xingming, int gongjili, int shengmingli) { // 构造函数：没有返回值，调用时机：初始化对象时调用
        // 作用：对类的成员变量做初始化
        atk = gongjili;
        hp = shengmingli;
        name = xingming;
        System.out.println("名称：" + name +
                "\n生命力：" + hp + "\n攻击力：" + atk + "\n");
    }

    Hero(String xingming, int gongjili, int shengmingli, int fangshouli) {
        atk = gongjili;
        hp = shengmingli;
        name = xingming;
        def = fangshouli;
        System.out.println("名称：" + name +
                "\n生命力：" + hp + "\n攻击力：" + atk + "\n");
    }

    void eat() {
        hp = hp + 50;
        System.out.println(name + "吃了一碗饭，血量+50，生命力 = " + hp);
        System.out.println();
    }

    void skill(Boss boss) {  // 针对 Boss类
        boss.hp = boss.hp - atk;
        System.out.println(name + "对黑暗暴军造成伤害-" + atk);
        System.out.println("黑暗暴军剩余血量=" + boss.hp);
        System.out.println();
    }

    void skill(Hero hero) {  // 针对 Hero类
        hero.hp = hero.hp - atk;
        System.out.println(name + "对" + hero.name + "造成伤害-" + atk);
        System.out.println(hero.name + "剩余血量=" + hero.hp);
        System.out.println();
    }
}
